package edu.uclmgmu.bacteriosec.aspects.com.mysql.jdbc.Connection;

import com.mysql.jdbc.*;
import java.sql.*;
import edu.uclmgmu.bacteriosec.aspects.common.Store;

privileged aspect Connection_Booleans {
	
	/** boolean */
	boolean around(com.mysql.jdbc.Connection caller) : target(caller) && 
	call(boolean com.mysql.jdbc.Connection.getCacheResultSetMetadata()) {
		String currentJoinPoint = Store.getCurrentjoinPoint();
		String signature=thisJoinPointStaticPart.getSignature().toString();
		if (currentJoinPoint.equals(signature)) {
			int numberOfCallInTurn = Store.getNumberOfCallInTurn(signature);
			int numberOfCurrentCall = Store.getNumberOfCurrentCall(signature);
			if (numberOfCallInTurn == numberOfCurrentCall) {
				Store.updateNumberOfCurrentCall(signature);
				return !proceed(caller);
			} else {
				Store.updateNumberOfCurrentCall(signature);
				return proceed(caller);
			}
		} else {
			return proceed(caller);
		}
	}

	boolean around(com.mysql.jdbc.Connection caller) : target(caller) && 
	call(boolean com.mysql.jdbc.Connection.getUseFastIntParsing()) {
		String currentJoinPoint = Store.getCurrentjoinPoint();
		String signature=thisJoinPointStaticPart.getSignature().toString();
		if (currentJoinPoint.equals(signature)) {
			int numberOfCallInTurn = Store.getNumberOfCallInTurn(signature);
			int numberOfCurrentCall = Store.getNumberOfCurrentCall(signature);
			if (numberOfCallInTurn == numberOfCurrentCall) {
				Store.updateNumberOfCurrentCall(signature);
				return !proceed(caller);
			} else {
				Store.updateNumberOfCurrentCall(signature);
				return proceed(caller);
			}
		} else {
			return proceed(caller);
		}
	}

	boolean around(com.mysql.jdbc.Connection caller) : target(caller) && 
	call(boolean com.mysql.jdbc.Connection.supportsQuotedIdentifiers()) {
		String currentJoinPoint = Store.getCurrentjoinPoint();
		String signature=thisJoinPointStaticPart.getSignature().toString();
		if (currentJoinPoint.equals(signature)) {
			int numberOfCallInTurn = Store.getNumberOfCallInTurn(signature);
			int numberOfCurrentCall = Store.getNumberOfCurrentCall(signature);
			if (numberOfCallInTurn == numberOfCurrentCall) {
				Store.updateNumberOfCurrentCall(signature);
				return !proceed(caller);
			} else {
				Store.updateNumberOfCurrentCall(signature);
				return proceed(caller);
			}
		} else {
			return proceed(caller);
		}
	}
	
	boolean around(com.mysql.jdbc.Connection caller) : target(caller) && 
	call(boolean com.mysql.jdbc.Connection.useMaxRows()) {
		String currentJoinPoint = Store.getCurrentjoinPoint();
		String signature=thisJoinPointStaticPart.getSignature().toString();
		if (currentJoinPoint.equals(signature)) {
			int numberOfCallInTurn = Store.getNumberOfCallInTurn(signature);
			int numberOfCurrentCall = Store.getNumberOfCurrentCall(signature);
			if (numberOfCallInTurn == numberOfCurrentCall) {
				Store.updateNumberOfCurrentCall(signature);
				return !proceed(caller);
			} else {
				Store.updateNumberOfCurrentCall(signature);
				return proceed(caller);
			}
		} else {
			return proceed(caller);
		}
	}

}
